package com.spider.spiderflowable.utils;

import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2025/4/20 5:24 下午
 */

@Slf4j
public class BeanUtils {


  private BeanUtils() {
  }

  public static List copyList(List<? extends Object> sourceList, Class targetClass) {//NOSONAR
    List targetList = new ArrayList();//NOSONAR
    Object target = null;
    for (Object source : sourceList) {
      try {
        target = targetClass.newInstance();
      } catch (InstantiationException | IllegalAccessException e) {
        log.error("BeanUtils.copyList error:", e);
      }
      org.springframework.beans.BeanUtils.copyProperties(source, target);//NOSONAR
      targetList.add(target);
    }
    return targetList;
  }

  public static <T> T copyBean(Object source, Class<T> targetClass, String... ignoreProperties) {
    T target = null;
    try {
      target = targetClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
      log.error("BeanUtils.copyList error:", e);
    }
    org.springframework.beans.BeanUtils.copyProperties(source, target, ignoreProperties);//NOSONAR
    return target;
  }

}
